package models

import (
	"time"

	"gorm.io/gorm"
)

type User struct {
	ID        uint           `json:"id" gorm:"primaryKey"`
	Username  string         `json:"username" gorm:"size:50;uniqueIndex;not null"`
	Email     string         `json:"email" gorm:"size:100;uniqueIndex;not null"`
	Password  string         `json:"-" gorm:"size:255;not null"` // JSON 序列化时忽略密码字段
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` // 支持软删除
	// 关联关系
	Articles []Article `json:"articles,omitempty" gorm:"foreignKey:AuthorID;constraint:OnDelete:CASCADE;"`
	Comments []Comment `json:"comments,omitempty" gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;"`
}
